extends Node2D


# Declare member variables here. Examples:
# var a = 2
# var b = "text"

export var potential_curve :Curve

var current_water_texture: Image
var current_water_ba: PoolByteArray

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

func _process(delta):
	#print ("updated")
	current_water_texture = $Viewport2.get_texture().get_data()
	current_water_ba = current_water_texture.get_data()
	#print ("size=", current_water_ba.size()/4/1024)
	#print ("raw pixel: ", value_at(5,5))

func field_at_vector(vec2):
	if vec2.x <0 or vec2.y<0:
		return Vector3.ZERO
	if vec2.x >1023 or vec2.y>599:
		return Vector3.ZERO
	return value_at(vec2.x, vec2.y)

func value_at(x,y):
	y = 599 - y
	var offset = (y * 1024 + x) * 4
	return Vector3(
		current_water_ba[offset]/255.0,
		current_water_ba[offset+1]/255.0,
		current_water_ba[offset+2]/255.0
		)
		
		


# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass
